package com.artqiyi.dollmachine.common.Base;

import android.content.Context;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;
import android.util.Log;

import com.artqiyi.artqiyisdk.ArtqiyiSDK;
import com.artqiyi.dollmachine.common.constant.Constant;
import com.artqiyi.dollmachine.model.MessageObservable;
import com.artqiyi.dollmachine.utils.SharedPre;
import com.tencent.TIMMessage;
import com.tencent.TIMMessageListener;
import com.tencent.TIMUserProfile;
import com.tencent.bugly.crashreport.CrashReport;
import com.tencent.ilivesdk.ILiveSDK;
import com.tencent.ilivesdk.core.ILiveRoomConfig;
import com.tencent.ilivesdk.core.ILiveRoomManager;
import com.tencent.ilivesdk.data.ILiveMessage;
import com.tencent.ilivesdk.data.msg.ILiveOtherMessage;
import com.tencent.ilivesdk.data.msg.ILiveTextMessage;
import com.tencent.ilivesdk.listener.ILiveMessageListener;
import com.tencent.livesdk.ILVCustomCmd;
import com.tencent.livesdk.ILVLiveConfig;
import com.tencent.livesdk.ILVLiveManager;
import com.tencent.livesdk.ILVText;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.List;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import timber.log.Timber;

public class BaseApp extends MultiDexApplication {

    private static BaseApp mApp;

    public static IWXAPI mWxApi;

    public static BaseApp getInstance() {
        if (mApp == null) {
            throw new RuntimeException("NullPointException caught at com.artqiyi.dollmachine.common.Base.BaseApp");
        }
        return mApp;
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(newBase);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mApp = this;

        initTimber();
        initArtqiyi();
//        initOkHttp();
//        initTXSDK();
        registToWX();
        initSharePre();
        initBugly();
    }

    private void initArtqiyi() {
        ArtqiyiSDK.getInstant().init();
    }

//    private void initOkHttp() {
//        OkHttpClient okHttpClient = new OkHttpClient.Builder()
//                .connectTimeout(10000L, TimeUnit.MILLISECONDS)
//                .readTimeout(10000L, TimeUnit.MILLISECONDS)
//                .cache(null)
//                //其他配置
//                .build();
//
//        OkHttpUtils.initClient(okHttpClient);
//    }

    // debug模式打印日志并使用本地内存泄漏跟踪
    private void initTimber() {
        Timber.plant(new Timber.DebugTree());
    }

//    //播放器
//    private void initTXSDK() {
//        ILiveSDK.getInstance().initSdk(getApplicationContext(), Constant.APP_ID, Constant.ACCOUNT_TYPE);
//        ILVLiveManager.getInstance().init(new ILVLiveConfig()
//                .setLiveMsgListener(MessageObservable.getInstance()));
//    }

    //微信登录
    private void registToWX() {
        mWxApi = WXAPIFactory.createWXAPI(this, Constant.WX_APP_ID, true);
        mWxApi.registerApp(Constant.WX_APP_ID);
    }

    private void initSharePre() {
        SharedPre.init(this, getPackageName());
    }

    private void initBugly() {
        CrashReport.initCrashReport(getApplicationContext(), Constant.BUGLY_ID, true);
    }

}
